Skip to content

fix(typescript-fetch): support non-default file names#24006

Open
celluj34 wants to merge 8 commits into
OpenAPITools:masterfrom
celluj34:jgc/fix-api-imports
Open

fix(typescript-fetch): support non-default file names#24006
celluj34 wants to merge 8 commits into
OpenAPITools:masterfrom
celluj34:jgc/fix-api-imports

Conversation

@celluj34

@celluj34 celluj34 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

files generated with non-default (e.g. "fileNaming": "kebab-case") have their import path set with the default file name. this PR fixes the non-barrel imports by using the parsed file name instead of simply the class name.

(fixes #23840)

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes broken model imports in the typescript-fetch generator when fileNaming is non-default (e.g., kebab-case). API files now import models using the actual generated file name instead of the class name.

  • Bug Fixes
    • Generate and use classFileName (via convertUsingFileNamingConvention) for model import paths in apis.mustache and sagas.mustache to support non-default fileNaming.
    • Added a test in TypeScriptFetchClientCodegenTest to assert kebab-case imports (e.g., ../models/pet not ../models/Pet) and set WITHOUT_RUNTIME_CHECKS to false to exercise imports.
    • Added bin/configs/typescript-fetch-kebab-case.yaml and regenerated samples under samples/client/petstore/typescript-fetch/builds/kebab-case for coverage.

Written for commit 80e5496. Summary will update on new commits.

Review in cubic

@celluj34 celluj34 marked this pull request as ready for review June 13, 2026 02:09
@celluj34

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 126 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/typescript-fetch/builds/kebab-case/docs/EnumClass.md">

<violation number="1" location="samples/client/petstore/typescript-fetch/builds/kebab-case/docs/EnumClass.md:16">
P2: EnumClass doc example uses object literal for a string union enum type, producing non-compilable TypeScript</violation>
</file>

<file name="samples/client/petstore/typescript-fetch/builds/kebab-case/docs/Capitalization.md">

<violation number="1" location="samples/client/petstore/typescript-fetch/builds/kebab-case/docs/Capitalization.md:19">
P2: Generated model doc contains an empty module specifier in the TypeScript example (`from ''`) because the build config does not set `npmName`, leaving the `model_doc.mustache` template variable unresolved.</violation>
</file>

<file name="samples/client/petstore/typescript-fetch/builds/kebab-case/docs/FormatTest.md">

<violation number="1" location="samples/client/petstore/typescript-fetch/builds/kebab-case/docs/FormatTest.md:45">
P2: UUID example value is emitted without quotes, resulting in invalid TypeScript syntax for a string field.</violation>
</file>

Note: This PR contains a large number of files. cubic only reviews up to 100 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.

Re-trigger cubic

import type { EnumClass } from ''

// TODO: Update the object below with actual values
const example = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: EnumClass doc example uses object literal for a string union enum type, producing non-compilable TypeScript

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/typescript-fetch/builds/kebab-case/docs/EnumClass.md, line 16:

<comment>EnumClass doc example uses object literal for a string union enum type, producing non-compilable TypeScript</comment>

<file context>
@@ -0,0 +1,32 @@
+import type { EnumClass } from ''
+
+// TODO: Update the object below with actual values
+const example = {
+} satisfies EnumClass
+
</file context>

## Example

```typescript
import type { Capitalization } from ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Generated model doc contains an empty module specifier in the TypeScript example (from '') because the build config does not set npmName, leaving the model_doc.mustache template variable unresolved.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/typescript-fetch/builds/kebab-case/docs/Capitalization.md, line 19:

<comment>Generated model doc contains an empty module specifier in the TypeScript example (`from ''`) because the build config does not set `npmName`, leaving the `model_doc.mustache` template variable unresolved.</comment>

<file context>
@@ -0,0 +1,44 @@
+## Example
+
+```typescript
+import type { Capitalization } from ''
+
+// TODO: Update the object below with actual values
</file context>

"binary": null,
"date": null,
"dateTime": null,
"uuid": 72f98069-206d-4f12-9f12-3d1e525a8e84,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: UUID example value is emitted without quotes, resulting in invalid TypeScript syntax for a string field.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/typescript-fetch/builds/kebab-case/docs/FormatTest.md, line 45:

<comment>UUID example value is emitted without quotes, resulting in invalid TypeScript syntax for a string field.</comment>

<file context>
@@ -0,0 +1,64 @@
+  "binary": null,
+  "date": null,
+  "dateTime": null,
+  "uuid": 72f98069-206d-4f12-9f12-3d1e525a8e84,
+  "password": null,
+  "patternWithDigits": null,
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][typescript-fetch] api model imports not using correct filename

1 participant